package com.jyw.router.hospital.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;

import com.jyw.router.common.annotation.Anonymous;
import com.jyw.router.common.core.domain.CommonResult;
import com.jyw.router.hospital.domain.dto.HospitalDicDto;
import com.jyw.router.hospital.domain.dto.HospitalRegisterDto;
import com.jyw.router.hospital.domain.vo.RegisterHospitalVo;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.jyw.router.common.annotation.Log;
import com.jyw.router.common.core.controller.BaseController;
import com.jyw.router.common.core.domain.AjaxResult;
import com.jyw.router.common.enums.BusinessType;
import com.jyw.router.hospital.domain.HospitalInfo;
import com.jyw.router.hospital.service.IHospitalInfoService;
import com.jyw.router.common.utils.poi.ExcelUtil;
import com.jyw.router.common.core.page.TableDataInfo;

/**
 * 医院服务信息Controller
 * 
 * @author shenjun
 * @date 2023-04-10
 */
@RestController
@RequestMapping("/hospital/hospitalInfo")
@Slf4j
@Api(tags = "医院信息接口")
public class HospitalInfoController extends BaseController
{
    @Autowired
    private IHospitalInfoService hospitalInfoService;

    /**
     * 查询医院服务信息列表
     */
    @PreAuthorize("@ss.hasPermi('hospital:hospitalInfo:list')")
    @GetMapping("/list")
    public TableDataInfo list(HospitalInfo hospitalInfo)
    {
        startPage();
        List<HospitalInfo> list = hospitalInfoService.selectHospitalInfoList(hospitalInfo);
        return getDataTable(list);
    }

    /**
     * 导出医院服务信息列表
     */
    @PreAuthorize("@ss.hasPermi('hospital:hospitalInfo:export')")
    @Log(title = "医院服务信息", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, HospitalInfo hospitalInfo)
    {
        List<HospitalInfo> list = hospitalInfoService.selectHospitalInfoList(hospitalInfo);
        ExcelUtil<HospitalInfo> util = new ExcelUtil<HospitalInfo>(HospitalInfo.class);
        util.exportExcel(response, list, "医院服务信息数据");
    }

    /**
     * 获取医院服务信息详细信息
     */
    @PreAuthorize("@ss.hasPermi('hospital:hospitalInfo:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return success(hospitalInfoService.selectHospitalInfoById(id));
    }

    /**
     * 新增医院服务信息
     */
    @PreAuthorize("@ss.hasPermi('hospital:hospitalInfo:add')")
    @Log(title = "医院服务信息", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody HospitalInfo hospitalInfo)
    {
        return toAjax(hospitalInfoService.insertHospitalInfo(hospitalInfo));
    }

    /**
     * 修改医院服务信息
     */
    @PreAuthorize("@ss.hasPermi('hospital:hospitalInfo:edit')")
    @Log(title = "医院服务信息", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody HospitalInfo hospitalInfo)
    {
        return toAjax(hospitalInfoService.updateHospitalInfo(hospitalInfo));
    }

    /**
     * 删除医院服务信息
     */
    @PreAuthorize("@ss.hasPermi('hospital:hospitalInfo:remove')")
    @Log(title = "医院服务信息", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(hospitalInfoService.deleteHospitalInfoByIds(ids));
    }

    @Log(title = "注册医院信息", businessType = BusinessType.INSERT)
    @PostMapping("register")
    @ApiOperation("注册医院信息")
    @PreAuthorize("@ss.hasPermi('hospital:hospitalInfo:add')")
    public CommonResult<HospitalRegisterDto> register(@RequestBody RegisterHospitalVo vo){
        log.info("请求注册医院信息:{}",vo);
        HospitalInfo info = hospitalInfoService.registerHospital(vo);
        return CommonResult.success("注册成功",info.buildDto());
    }


    @GetMapping("dict")
    @ApiOperation("查询启用的所有医院")
    @Anonymous
    public CommonResult<List<HospitalDicDto>> dictList(){
        List<HospitalDicDto> dicDtoList = hospitalInfoService.dictList();
        return CommonResult.success("查询成功",dicDtoList);
    }
}
